package giermala.dominik.fotka.controller;

import giermala.dominik.fotka.dao.FotoDao;
import giermala.dominik.fotka.domain.Foto;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ImageController {

	private static final Logger logger = LoggerFactory.getLogger(ImageController.class);
	
	@Autowired
    private FotoDao fotoDao;
	
	@RequestMapping(value = "/imageController/{imageId}", method = RequestMethod.GET)
	@ResponseBody
	public byte[] loadImage(@PathVariable long imageId)  {
		logger.info("You are loading image");
		Foto foto = fotoDao.findById(imageId);
		return foto.getImage();
	}
}
